package cn.xiaopengstack.domain.strategy.repository;

import cn.xiaopengstack.domain.strategy.model.entity.StrategyAwardEntity;
import cn.xiaopengstack.domain.strategy.model.entity.StrategyEntity;
import cn.xiaopengstack.domain.strategy.model.entity.StrategyRuleEntity;
import cn.xiaopengstack.domain.strategy.model.valobj.*;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author jiangyangang
 */
public interface IStrategyRepository {
    /**
     * 获取策略下的所有奖品信息
     * @param strategyId
     * @return
     */
    List<StrategyAwardEntity> queryStrategyAwardInfoList(Long strategyId);

    /**
     * 存储策略搜索表
     * @param key 缓存键
     * @param rateRange 表大小
     * @param shuffleStrategyAwardSearchRateTable 搜索表实体
     */
    void storeStrategyAwardSearchRateTable(String key, Integer rateRange, Map<Integer, Integer> shuffleStrategyAwardSearchRateTable);

    /**
     * 获取奖品概率的范围值
     * @param strategyId
     * @return
     */
    Integer getRateRange(Long strategyId);

    int getRateRange(String key);

    /**
     * 获取奖品（抽奖）
     * @param strategyId
     * @param rateKey
     * @return
     */
    Integer getStrategyAwardAssemble(Long strategyId, Integer rateKey);

    StrategyEntity queryStrategyEntityByStrategyId(Long strategyId);

    StrategyRuleEntity queryStrategyRule(Long strategyId, String ruleModel);

    /**
     * 查询奖品信息
     * @param strategyId
     * @param awardId
     * @return
     */
    StrategyAwardEntity queryStrategyAward(Long strategyId, Integer awardId);

    /**
     * 查询规则值
     * @param strategyId
     * @param awardId
     * @param ruleModel
     * @return
     */
    String queryStrategyRuleValue(Long strategyId, Integer awardId, String ruleModel);

    String queryStrategyRuleValue(Long strategyId, String ruleModel);

    /**
     * 查询奖品规则配置
     * @param strategyId
     * @param awardId
     * @return
     */
    StrategyAwardRuleModelVO queryStrategyAwardRuleModelVO(Long strategyId, Integer awardId);

    /**
     * 组装树节点
     * @param treeId
     * @return
     */
    RuleTreeVO queryRuleTreeVOByTreeId(String treeId);

    /**
     * 缓存奖品库存
     * @param awardStockVO
     */
    void cacheStrategyAwardStock(AssembleAwardStockVO awardStockVO);

    /**
     * 扣减库存缓存
     * @param stockVO
     * @return
     */
    boolean decrStrategyAwardStock(StrategyAwardDecrStockVO stockVO);

    /**
     * 扣减库存成功动作放入队列
     * @param awardStockQueueVO
     */
    void produceStrategyAwardDecrStockQueue(AwardStockQueueVO awardStockQueueVO);

    /**
     * 获取扣除库存队列
     * @param awardStockQueueVO
     */
    AwardStockQueueVO consumeStrategyAwardDecrStockQueue(AwardStockQueueVO awardStockQueueVO);

    /**
     * 更新奖品的DB库存
     * @param updateAwardStockVO
     */
    void updateStrategyAwardStock(UpdateAwardStockVO updateAwardStockVO);

    /**
     * 获取当前已经生效的奖品ID
     * @return
     */
    Set<AwardStockQueueVO> getCacheAwardRegisterTable();

    /**
     * 查询所有的奖品
     * @param activityId
     * @return
     */
    List<StrategyAwardEntity> queryStrategyAwardInfoListByActivityId(Long activityId);
}
